package com.david.zhufengfm.utils;

import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;

/**
 * Created by David on 2015/10/22.
 * qq:978944820
 */
public final class DimensionUtil {
    private DimensionUtil(){

    }

    /**
     * 根据当前手机的屏幕密度，进行dp到px单位的换算
     * @param context
     * @param dp 待转换的内容
     * @return px像素
     */
    public static int dp2px(Context context,int dp){
        int ret=0;
        Resources res=context.getResources();
        //获取屏幕的测量信息
        DisplayMetrics metrics = res.getDisplayMetrics();
        //px=dp*(dpi/160)
        ret= (int) (metrics.density*dp);
        return ret;
    }
}
